<?php

namespace apiend\modules\user\controllers;

use Yii;
use apiend\components\Controller;
use apiend\modules\user\models\AdminerForm;
use apiend\modules\user\models\UserSearch;

/**
 * 人员管理接口
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class DefaultController extends Controller {

    /**
     * @inheritdoc
     */
    protected function rules() {
        return [
            [
                'allow' => true,
                'roles' => ['@'],
            ],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public $modelClass = UserSearch::class;

    /**
     * 人员管理
     * @return mixed
     */
    public function actionIndex() {
        /* @var $model UserSearch */
        $model = new $this->modelClass;
        return $model->configs();
    }

    /**
     * 人员管理
     * @return mixed
     */
    public function actionList() {
        /* @var $model UserSearch */
        $model = new $this->modelClass;
        $model->load(Yii::$app->request->getQueryParams(), '');
        return $model->search();
    }

    /**
     * 维护人员
     * @return mixed
     */
    public function actionUpdate($id) {
        $model = new AdminerForm();
        $model->user_id = $id;
        $params = Yii::$app->request->post();
        if (!$model->load($params, '')) {
            parent::error('数据提交失败');
        }
        return $model->save();
    }

}
